package madixin.t203;

import madixin.ListNode;

public class Solution {
    public ListNode removeElements(ListNode head, int val) {
        ListNode dummy = new ListNode(0);
        dummy.next = head;
        ListNode cur = dummy;
        while (cur != null && cur.next != null) {
            if (cur.next.val != val){
                cur = cur.next;
            }else{
                ListNode temp = cur.next;
                while (temp != null && temp.val == val){
                    temp = temp.next;
                }
                cur.next = temp;
                cur = temp;
            }
        }


        return dummy.next;

    }
}
